/*
 * @(#)NacosConfingController.java 2021/3/27
 *
 * Copyright (c) 2010 by rayootech.com. All rights reserved.
 */
package com.nuctech.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Nacos配置控制器
 *
 * @author lilu
 * @date 2021/3/27 6:43 下午
 * @since 1.0.0
 */
@RestController
// 只需要在需要动态读取配置类上添加该注解就可以实现配置自动刷新【推荐使用】
@RefreshScope
public class NacosConfingController {

	@Value("${config.appName}")
	private String appName;

	@Value("${config.env}")
	private String env;

	@Autowired
	private ConfigurableApplicationContext applicationContext;

	@GetMapping("test-config1")
	public String testConfig1() {
		// 默认支持配置中心动态刷新
		return this.applicationContext.getEnvironment().getProperty("config.appName");
	}

	@GetMapping("test-config2")
	public String testConfig2() {
		return this.appName;
	}

	@GetMapping("test-config3")
	public String testConfig3() {
		return this.env;
	}

}
